package listbyorder.access101_200.test167;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/14 12:46
 */
public class Solution2 {

    // 方法二： 双指针求解方法
    public int[] twoSum(int[] numbers, int target) {
        int l = 0;
        int r = numbers.length - 1;
        while (l < r) {
            if (numbers[l] + numbers[r] == target) {
                return new int[]{l + 1, r + 1};
            } else if (numbers[l] + numbers[r] < target) {
                l++;
            } else {
                r--;
            }
        }
        throw new RuntimeException("没有找到");
    }
}
